package com.example.module_motocircle.model

import android.content.Context
import androidx.core.content.ContextCompat
import com.example.lib_common.widget.nine_pics.Image
import com.example.module_motocircle.R

data class PostListModel(
    val current: Int?,
    val pages: Int?,
    val records: List<PostItem>?,
    val size: Int?,
    val total: Int?
)

data class PostItem(
    val aftersale_result: String?,
    val aftersale_status: Int?,
    val aftersale_time: String?,
    val avatar: Avatar?,
    val category_str: String?,
    val channel: Int?,
    val channel_str: String?,
    var collect_number: Int=0,
    val comment_number: Int=0,
    val content: String?,
    val create_by: String?,
    val create_time: String?,
    val delflag: Int?,
    val hot_sort: Int?,
    val if_aftersale: Int?,
    val if_all_sehicle_model: Int?,
    val if_all_series: Int?,
    val if_audit: Int?,
    var if_collect: Int?,
    val if_hot: Int?,
    var if_like: Int=0,
    val if_my: Int?,
    val if_recommend: Int?,
    val if_sensitive: Int?,
    val if_tip_off: String?,
    val if_transcode: Int?,
    val if_up: Int?,
    val if_up_str: String?,
    val if_video: Int?,
    val image: List<Image>?,
    val img_ids: String?,
    val lat: Double?,
    var like_number: Int=0,
    val list_show_time: String?,
    val location: String?,
    val lon: Double?,
    val model_name: String?,
    val model_nickname: String?,
    val posts_id: String="",
    val recommend_sort: Int?,
    val relation: Int?, //好友关系(0:无关系 1:粉丝 2:已关注 3:相互关注)
    val search_sort: Int?,
    val series: String?,
    var share_number: Int=0,
    val tip_off_number: Int?,
    val topic_ids: String?,
    val topic_str: String?,
    val topics: List<Topicc>?,
    val update_by: String?,
    val update_name: String?,
    val update_time: String?,
    val user_id: String?,
    val vehicle_model_id: String?,
    val virtual_like_number: Int=0,
    val virtual_share_number: Int=0,
    val weight_score: Double?,
    // 是否需要展示关注状态，某些特定页面是不展示的
    var needShowFollowState: Boolean? = null
){
    fun requireName():String{
        return if(isOfficial()){
            "宗申骑士俱乐部官方"
        }else{
            model_nickname?:""
        }
    }
    //显示subName  官方-显示赛科龙官方发布 其他-显示modelName
    fun requireSubName(): String {
        return if (isOfficial()) {
            "宗申骑士俱乐部官方发布"
        } else {
            model_name?:""
        }
    }
    /**
     * 是否官方发布帖子
     */
    fun isOfficial() = channel == 1

    //显示颜色 官方-显示主题色 其他-显示黑色
    fun requireNameColor(context: Context): Int {
        return if (isOfficial()) {
            ContextCompat.getColor(context, R.color.color_d8000f)
        } else {
            ContextCompat.getColor(context, R.color.color_101010)
        }
    }

    //显示关注状态
    fun showFollowState(): Boolean {
        if (needShowFollowState == null)
            needShowFollowState = true

        // 非官方 非自己 非关注列表 才需要显示关注关系
        return channel != 1 && needShowFollowState == true && relation != UserRelationEnum.MYSELF.relation
    }
    /**
     * +关注
     */
    fun showAddIcon(): Boolean {
        return relation!! <= UserRelationEnum.FANS.relation
    }
    /**
     * 互关
     *     NONE(0, "无关系"),
     *     FANS(1, "粉丝"),
     *     FOCUS(2, "已关注"),
     *     FRIENDS(3, "互相关注"),
     *     MYSELF(4, "我自己"),
     */
    fun showMutualIcon(): Boolean {
        return relation == UserRelationEnum.FRIENDS.relation
    }
    fun hasFollowed(): Boolean {
        return relation in listOf(
            UserRelationEnum.FOCUS.relation,
            UserRelationEnum.FRIENDS.relation
        )
    }
/*
关注状态
 */
    fun followStateName(): String {
        return when (relation) {
            UserRelationEnum.NONE.relation -> {//0
                "关注"
            }

            UserRelationEnum.FANS.relation -> {//0
                "关注"
            }

            UserRelationEnum.FOCUS.relation -> {//2
                "已关注"
            }

            UserRelationEnum.FRIENDS.relation -> {//3
                "互相关注"
            }

            else -> {
                ""
            }
        }
    }
    //格式化点赞数显示
    fun formatLikeNumber(): String {
        val total = like_number + virtual_like_number
        return if (total < 10_000) {
            total.toString()
        } else if (total > 10_000) {
            String.format("%sw+", total / 10_000)
        } else {
            "1w"
        }
    }

    //格式化收藏数显示
    fun formatCollectionNumber(): String {
        val total = collect_number
        return if (total < 10_000) {
            total.toString()
        } else if (total > 10_000) {
            String.format("%sw+", total / 10_000)
        } else {
            "1w"
        }
    }
    //格式化评论数
    fun formatCommentNumber(): String {
        return if (comment_number < 10_000) {
            comment_number.toString()
        } else if (comment_number > 10_000) {
            String.format("%sw+", comment_number / 10_000)
        } else {
            "1w"
        }
    }
    //格式化分享数显示
    fun formatShareNumber(): String {
        val total = share_number + virtual_share_number
        return if (total < 10_000) {//小于
            total.toString()
        } else if (total > 10_000) {//大于
            String.format("%sw+", total / 10_000)
        } else {//等于一万
            "1w"
        }
    }
}
/** enum */
/** 好友关系(0:无关系 1:粉丝 2:已关注 3:相互关注 4:我自己) */
enum class UserRelationEnum(val relation: Int, val typeName: String) {
    NONE(0, "无关系"),
    FANS(1, "粉丝"),
    FOCUS(2, "已关注"),
    FRIENDS(3, "互相关注"),
    MYSELF(4, "我自己"),
}

data class Avatar(
    val contentLength: Int?,
    val contentType: String?,
    val filename: String?,
    val firstImage: String?,
    val id: Int?,
    val imageHeight: Int?,
    val imageWidth: Int?,
    val thumbnailUrl: String?,
    val url: String?
)



data class Topicc(
    val topicId: String?,
    val topicName: String?
)